package com.example.demo.intercepter;


import com.example.demo.domian.UserVo;
import com.example.demo.common.utils.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Name MyIntercepter
 * @Description
 * @Author wen
 * @Date 2020-03-28
 */
public class MyIntercepter implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        if (handler instanceof HandlerMethod) {
//            HandlerMethod handlerMethod = (HandlerMethod) handler;
//            //获取方法注解
//            AccessLimit accessLimit = handlerMethod.getMethodAnnotation(AccessLimit.class);
//            if (accessLimit != null) {
//                boolean needLogin = accessLimit.needLogin();
//                //1.判断用户是否需要登录
//                if (needLogin && (ShiroUtil.getUser() == null)) {
//                    ResponseUtil.writer(response, EmError.USER_NOT_LOGGED_IN);
//                    return false;
//                }
//                //2.判断访问限制
//                long seconds = accessLimit.seconds();
//                int maxCount = accessLimit.maxCount();
//                if (seconds > 0 && maxCount > 0) {
//
//                }
//            }
//        }
            //检查是否限制用户访问接口
//		if(!this.checkAccessLimit(handler, request, response)){
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }

}
